package chessGame.piece;

import chessGame.Board;
import chessGame.annotation.PieceInfo;
import chessGame.move.QueenMoveStrategy;
import chessGame.utils.MoveUtils;
import chessLib.Position;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
 * @BelongsProject: chessGame
 * @BelongsPackage: chessGame
 * @CreateTime: 2025-09-30  09:21
 * @Description: TODO
 * @Version: 1.0
 */
@PieceInfo(value = "Queen")
public class Queen extends Piece{
    private final QueenMoveStrategy queenMove;

    public Queen() {
        super("Queen");
        this.queenMove = new QueenMoveStrategy();
    }
    public Queen(String pieceName) {
        super(pieceName);
        this.queenMove = new QueenMoveStrategy();
    }

    /*@Override
    public Set<Position> getValidMoves(Position currentPosition, Board board) {
        Set<Position> validMoves = new HashSet<>();
        int row = currentPosition.getRow();
        int col = currentPosition.getCol();

        // 检查所有八个方向：水平、垂直和对角线
        int[][] directions = {
                {-1, -1}, {-1, 0}, {-1, 1},
                {0, -1},           {0, 1},
                {1, -1},  {1, 0},  {1, 1}
        };

        for (int[] direction : directions) {
            int dRow = direction[0];
            int dCol = direction[1];

            //朝这个方向移动，直到我们到达棋盘边界
            for (int i = 1; ; i++) {
                int newRow = row + i * dRow;
                int newCol = col + i * dCol;

                // 检查当前位置是否在棋盘边界内
                if (newRow >= 1 && newRow <= 8 && newCol >= 1 && newCol <= 8) {
                    Position newPosition = new Position(newRow, newCol);

                    // 如果这个位置被占用，则停止在这个方向上的移动
                    if (board.isOccupied(newPosition)) {
                        break;
                    }

                    validMoves.add(newPosition);
                } else {
                    // 超过棋盘边界
                    break;
                }
            }
        }

        return validMoves;
    }*/


    @Override
    public Set<Position> getValidMoves(Position currentPosition, Board board) {
        Collection<Position> positions = queenMove.validMovesFor(currentPosition);
        return MoveUtils.deduplication(positions, board);
    }

    @Override
    public String getName() {
        return "Queen";
    }
}
